var wx_alert = require('./wx_alert.js');
var app = getApp();
var url_request = "https://www.yunlianmen.com/ylm";
var url = "https://www.yunlianmen.com/ylmFile";
//post
function request(request_url,data, fun) {

  wx_alert.loadding("加载中");
  data.token = wx.getStorageSync("token");
  data.lit = wx.getStorageSync("lit");
  data.lat = wx.getStorageSync("lat");
  wx.request({
    url: url_request + request_url, 
    data: data,
    method: "POST",
    header: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    success: function (res) {
      fun && fun(res.data);
      setTimeout(function () {
        wx_alert.hideLoading();
      }, 300)
    }
  })
}

//get
function Get(get_url, data, fun){
  wx.request({
    url: url_request + get_url  + data,
    success:function(res){
      fun && fun(res.data)
    }
  })
}

//跳转
function turn(e){
  var url = e.currentTarget.dataset.url;
  var types = e.currentTarget.dataset.types;
  if (types=="reLunch"){
    console.log(1111)
    wx.reLaunch({
      url: url,
    })
  }else{
    wx.navigateTo({
      url: url,
    })
  }

}
//快捷导航
function close_modal() {
  var show_have = this.data.show_have;
  show_have = !show_have;
  this.setData({
    show_have: show_have
  })
}


module.exports = {
  request: request,
  turn: turn,
  close_modal: close_modal,
  Get: Get,
  url:url,
  url_request:url_request 
}